{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x = \n",
      "[1.76405235 0.40015721 0.97873798]\n",
      "y = \n",
      "[ 2.2408932   1.86755799 -0.97727788]\n",
      "\n",
      " Inner product of vectors: \n",
      "3.7438707148552592\n",
      "3.7438707148552592\n",
      "3.7438707148552592\n"
     ]
    }
   ],
   "source": [
    "# 向量内积、外积与克罗内克积\n",
    "\n",
    "np.random.seed(0)\n",
    "dim = 3\n",
    "x = np.random.randn(dim, )\n",
    "y = np.random.randn(dim, )\n",
    "print('x = ')\n",
    "print(x)\n",
    "print('y = ')\n",
    "print(y)\n",
    "\n",
    "print('\\n Inner product of vectors: ')\n",
    "print(np.inner(x, y))\n",
    "print(np.dot(x, y))\n",
    "print(x.dot(y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x = \n",
      "[1.76405235 0.40015721 0.97873798]\n",
      "y = \n",
      "[ 2.2408932   1.86755799 -0.97727788]\n",
      "\n",
      " Outer product of vectors:\n",
      "[[ 3.95305291  3.29447005 -1.72396934]\n",
      " [ 0.89670957  0.74731679 -0.39106479]\n",
      " [ 2.19324729  1.82784994 -0.95649898]]\n",
      "\n",
      " Kronecker  product of vectors:\n",
      "[ 3.95305291  3.29447005 -1.72396934  0.89670957  0.74731679 -0.39106479\n",
      "  2.19324729  1.82784994 -0.95649898]\n",
      "[[ 3.95305291  3.29447005 -1.72396934]\n",
      " [ 0.89670957  0.74731679 -0.39106479]\n",
      " [ 2.19324729  1.82784994 -0.95649898]]\n"
     ]
    }
   ],
   "source": [
    "# 向量的外积与克罗内克积\n",
    "\n",
    "print('x = ')\n",
    "print(x)\n",
    "print('y = ')\n",
    "print(y)\n",
    "\n",
    "print('\\n Outer product of vectors:')\n",
    "u = np.outer(x, y)\n",
    "print(u)\n",
    "\n",
    "print('\\n Kronecker  product of vectors:')\n",
    "v = np.kron(x, y)\n",
    "print(v)\n",
    "print(v.reshape(3, 3))\n",
    "\n",
    "# -----------------------------------------\n",
    "# 练习：如何操作可从u可获得v？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "m = \n",
      "[[ 0.95008842 -0.15135721 -0.10321885]\n",
      " [ 0.4105985   0.14404357  1.45427351]\n",
      " [ 0.76103773  0.12167502  0.44386323]]\n",
      "x = \n",
      "[1.76405235 0.40015721 0.97873798]\n",
      "\n",
      " m matrix-multiply x = \n",
      "[1.51441481 2.20531004 1.82562532]\n",
      "\n",
      " m matrix-multiply m = \n",
      "[[ 0.76196752 -0.17816392 -0.36399687]\n",
      " [ 1.55600596  0.13555026  0.81259578]\n",
      " [ 1.11080937 -0.04365498  0.29540988]]\n",
      "\n",
      " trace of m = \n",
      "1.537995221431893\n"
     ]
    }
   ],
   "source": [
    "# 矩阵相关计算\n",
    "\n",
    "m = np.random.randn(dim, dim)\n",
    "print('m = ')\n",
    "print(m)\n",
    "print('x = ')\n",
    "print(x)\n",
    "print('\\n m matrix-multiply x = ')\n",
    "print(m.dot(x))\n",
    "\n",
    "print('\\n m matrix-multiply m = ')\n",
    "print(m.dot(m))\n",
    "\n",
    "print('\\n trace of m = ')\n",
    "print(m.trace())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The shape of C = \n",
      "(5, 2, 6, 4)\n"
     ]
    }
   ],
   "source": [
    "# 张量相关计算: tensordot\n",
    "\n",
    "A = np.random.randn(5, 3, 2)\n",
    "B = np.random.randn(3, 6, 4)\n",
    "C1 = np.tensordot(A, B, [[1], [0]])\n",
    "print('The shape of C = ')\n",
    "print(C1.shape)\n",
    "\n",
    "# -----------------------------------------\n",
    "# 练习：使用reshape，transpose和dot实现上述tensordot运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The shape of the resulting tensor = \n",
      "(5, 6, 4)\n",
      "\n",
      " The illustration of the tensor-network contraction:\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQ0AAADnCAYAAAAEugNYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO2df1BU97n/39xgANnALvlBghrZok5+0LA0UpswQWiu2Nu05YfTqbVBoZ3eK5m5BRJsZr6asEZtppVEvG2D96bJbkK+Gb/TBjDf3tyKbUE6mFrtsKQkZhQumyBENMLBLgIDDvePved4dvfsj7N79vx8XjPMnN1z9pzH49n3Pp/neT7PJ2FpaQkEQRCR8g9KG0AQhLYg0SAIQhQkGgRBiIJEgyAIUZBoEAQhisQw+ym1QhDGJUHoTfI0CIIQBYkGQRCiINEgCEIUJBoEQYiCRIMgCFGEy54QcWZu8hImB09hfmoCVwf7MD854bM/t7YZ6WvyIj5f3zObYrKn8KUToo6X+3oXjh7E5TNdSMrIRHpOHpIsmbiroBTJGXfHZAcROSQaCjAzNoyRY61YnPNgZmw45LFzU5eQjshFQ+/cmJ0BAMxPTuDyZBcAYLSrDUkZmTBlrcE9j1WIEllCPCQaMjDe247RrjYsznpEf9bf8zA6nvEhwffnJycwP+n11vhYy2qRnpOH1BU5cphnCEg04szgK42YHh6I+vPzUyQaLHOTl0SL6MixVm47dUUOVpVW4fbcQqlNMxQkGnHmzoJNokSDdbOTMjKRZMlEapa4X0ixMYJYkfN6iSkmZBVVCsZ+IiH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OPfzpHFbrfH2SIinpBoEJLhPzQxm804efKkzzq9ZrOZREPj0PCEkIy8vMCFn/gd5m02G/r7++U0iYgDCUtLS6H2h9xJEE6nEzU1NQC8PV/NZrPPfrZCtL6+HocOHZLdPiImBMt7STSImMjPz+e6x/OfJYZhYLFYYLPZ0NHRgezsbIUsJGKARIOQHv5cE/ZZcrvdaGhoQGdnp6D3QWgGQdGgQCghCdnZ2WAYBiUlJYKeB6EfyNMgYoL1NGw2G8xms0+mhERD8wh6GpQ9IaKGvxJeU1MTuru7KXZhAEg0iKg5fPgwAK+XwdZo8DMktC6vPqHhCREVbHYEABwOB6qrq7l97JClvLwcHR0dSphHSANlTwjpaGlpQUNDA4DA2IVQRoXQJBTTIKTj5MmToj9D5eP6gESDiIpgk9QA37hGS0sLN5Q5duwYtQTUATQ8IaKCHYKYzWZMTU0F7G9oaPCZ4UrxDU0SVUyDIAjCBxqeEAQhChINgiBEQaJBEIQoSDQIghAFiQZBEKIg0SAIQhT/A4Sp2PkOV2CZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 张量相关计算: einsum\n",
    "\n",
    "A = np.random.randn(5, 3, 3)\n",
    "B = np.random.randn(6, 3, 3)\n",
    "C = np.random.randn(4, 3, 3)\n",
    "T = np.einsum('iab,jbc,kca->ijk', A, B, C)\n",
    "\n",
    "print('The shape of the resulting tensor = ')\n",
    "print(T.shape)\n",
    "print('\\n The illustration of the tensor-network contraction:')\n",
    "\n",
    "import PlotFun as pf\n",
    "pf.im_read_and_show('./Imgs/contract.png')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
